package com.soryin.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import com.soryin.entity.User;
import com.soryin.service.UserService;

@Controller		//注解该类为 controller
@RequestMapping("/login")		//用于处理 /login 
public class LoginController {
	
	@Autowired
	private UserService userService;
	
	
	@RequestMapping("/SinaWB")
	public void sinaWB(User user,HttpServletRequest request,HttpServletResponse response) throws IOException{
		
		
		//生成 json 数据
		String json = new JSONObject(user).toString();
		System.out.println("JSON"+json);
		
		//生成 json 数据
		//String result = "{\"photo\":\" "+ user.getPhoto() +" \",\"name\":\" "+ user.getName()+" \"}";
		
		//返回Session数据
		response.setContentType("application/json");
		PrintWriter out = response.getWriter();
		out.write(json);
		System.out.println("------------");
		List<User> users=userService.finAll();
		for (User u : users) {
			System.out.println("--"+u.getUsername());
		}
		
	}
	
	@ResourceMapping("/showUser")
	public void show(HttpServletRequest request,HttpServletResponse response) throws IOException{
		System.out.println("------------");
		List<User> users=userService.finAll();
		for (User user : users) {
			System.out.println("--"+user.getUsername());
		}
	}
	
	
	
	
}
